home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8563 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: ip-salem3-09.teleport.com!user
  2. From: dynamix@teleport.com (Steve Budrys)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: OOPS! - Re: How to delete array of pointers?
  5. Date: Wed, 14 Feb 1996 16:56:20 -0800
  6. Organization: Dynamix Trading
  7. Message-ID: <dynamix-1402961656200001@ip-salem3-09.teleport.com>
  8. References: <4fgvsu$5q4@eng_ser1.erg.cuhk.hk> <4fi8rd$738@reader2.ix.netcom.com> <4fkv8j$kb@cloner3.netcom.com>
  9. NNTP-Posting-Host: ip-salem3-09.teleport.com
  10.  
  11. In article <4fkv8j$kb@cloner3.netcom.com>, swampwiz@ix.netcom.com(Jean P.
  12. Laborde ) wrote:
  13.  
  14. > OOPS !
  15. > In <4fi8rd$738@reader2.ix.netcom.com> swampwiz@ix.netcom.com(Jean P.
  16. > Laborde ) writes: 
  17. > >In <4fgvsu$5q4@eng_ser1.erg.cuhk.hk> ywleung@cs.cuhk.hk (Marty McFly)
  18. > >writes: 
  19. > >>If I write the following code in a function:
  20. > >>      int** ptr;
  21. > >>      ptr = new int*[1000];
  22. > >>Is this code means allocating 1000 integer pointers which is pointed
  23. > >by ptr?
  24. > >>And then somehow I assign integer variable to ptr[0], ptr[1], ... and
  25. > >so on.
  26. > >>So at the end of the function, how can I reclaim just those pointers?
  27. > >The key
  28. > >>point is that those integer variable assigned to the pointers should
  29. > >not be 
  30. > >>deleted.
  31. > I mistakenly said:
  32. > >
  33. > >for(int i=0;i<1000;i++)
  34. > >    delete ptr[i];
  35. > >delete ptr;
  36. > I should have said at the last line
  37. > delete ptr [];
  38.  
  39. Why correct only that part and leave the serious error alone? He
  40. never said that he 'newed' any memory to those pointers, and he
  41. _did_ say that he did not want to affect to what those pointers pointed.
  42.  
  43. -- 
  44. Steve Budrys
  45. Dynamix Trading
  46.